package com.example.nit.listener;

import com.example.nit.whole.Reference;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhao
 * @date 2022/12/10 11:02
 **/
@Component
public class SparkStreaming3Listener {
    public List<String> list = new ArrayList<>();

    @KafkaListener(id = "consumer3", groupId = "niit03", topicPartitions = {
            @TopicPartition(topic = "streaming3", partitions = "0")
    })
    public List<String> res3(List<ConsumerRecord<?, ?>> records) {
        for (ConsumerRecord<?, ?> record : records) {

            list.add((String) record.value());
        }
        System.out.println(list);
        Reference.Streaming3List = list;
        return list;
    }
}
